import { post } from '@/service/request.js'

export default {

  // 带_ic的是标识，表示需要在data中设置一个响应式数据

  // 密码校验 1.密码  2.password_ic 标识
  changePassword(password, password_ic) {// eslint-disable-line
    if (password) {
      if (/^[a-zA-Z\d_]{8,16}$/.test(password) == false) {
        this.$message.error('格式为8~16、字符、数字');
        return
      } else {
        password_ic = true
      }
    }
    this.resetData()
  },
  // 手机改变 1.手机号 2.手机标识
  changePhone(phone, phone_ic) {// eslint-disable-line
    if (phone) {
      if (/^1[34578]\d{9}$/.test(phone) == false) {
        this.$message.error("请输入正确的手机号");
        return;
      } else {
        phone_ic = true
      }
    }
    this.resetData()
  },
  // 验证码检验 1.code 验证码
  verifyCode(code, code_ic) {// eslint-disable-line
    if (code) {
      if (typeof (code) == "string") {
        code_ic = true
      }
    }
    this.resetData()
  },

  // 点击查密码看功能 1.password_ic input内v-bind 2.icon 图标标识
  showPass(password_ic, icon_ic) {// eslint-disable-line
    //点击图标是密码隐藏或显示
    if (password_ic == "text") {
      password_ic = "password";
      //更换图标
      icon_ic = "el-input__icon el-icon-view";
    } else {
      password_ic = "text";
      icon_ic = "el-input__icon el-icon-loading";
      setTimeout(() => {
        // 清除图片
        icon_ic = "";
        focus();
      }, 200);
    }
  },


  //密码失焦事件
  onBlur(password_ic, icon_ic) {// eslint-disable-line
    password_ic = "password";
    icon_ic = "el-input__icon el-icon-view";
    this.changePassword()
  },

  // 同意条约
  clickCheck(isChecked_ic) { // eslint-disable-line
    isChecked_ic = !ischecked_ic // eslint-disable-line
    this.resetData()
  },


  // 按钮样式即统一样式
  resetData(requestBtn, registerBtn, { phone, password, verify, ischecked }) {
    if (phone & password & verify & ischecked) {
      requestBtn = true
    } else {
      registerBtn = false
    }
  },

  // 登录提交   1.data 提交的数据 2。url 提交的路径 3.{ 电话,密码,验证码,同意文聘条件 }
  submitBtn(data, url, { phone_ic, password_ic, verify_ic, ischecked_ic }) {
    if (phone_ic && password_ic && verify_ic && ischecked_ic) {
      post(url, data).then(res => {
        console.log(res);
        if (res.data.code == 0) {
          this.$message({ message: res.data.msg, type: 'success' })
        } else {
          this.$message.error(res.data.msg)
        }
      })
    }
  }
}